package com.jing.mapper;

import com.jing.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //根据用户名查询用户
    @Select("select * from user where username=#{username} and role=#{role}")
    User findByUserName(String username,String role);

    //添加
    @Insert("insert into user(username,password,nickname, email, phone_number,create_time,update_time,img_url)" +
            " values(#{username},#{password},#{nickname},#{email},#{phoneNumber},now(),now(),#{imgUrl})")
    void add(String username, String password,String nickname,String email,String phoneNumber,String imgUrl);

    @Update("update user set nickname=#{nickname},email=#{email},phone_number=#{phoneNumber},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    @Update("update user set img_url=#{avatarUrl},update_time=now() where id=#{id}")
    void updateAvatar(String avatarUrl,Integer id);

    @Update("update user set password=#{md5String},update_time=now() where id=#{id}")
    void updatePwd(String md5String, Integer id);




    @Select("select role from user where id=#{id} and username=#{username};")
    int findRole(Integer id, String username);

    List<User> getUserList(Integer userId, String username, String role,String state);

    @Delete("delete from user where id=#{id};")
    void deleteById(Integer id);

    List<User> getBlackUserList(Integer userId, String username, String role,String state);

    @Update("update user set state=#{state} where id=#{id};")
    void updateState(Integer id,String state);

    @Select("select score from user where id=#{userId};")
    int findUserById(Integer userId);

    @Update("update user set score=#{score} where id=#{userId};")
    void updateUserScore(Integer userId, int score);

    @Select("select id from user where username=#{username};")
    int selectIdByName(String username);
}
